import collections
class Solution(object):
    def getHint(self, secret, guess):
        """
        :type secret: str
        :type guess: str
        :rtype: str
        """
        B = 0
        C = 0
        d1 = collections.defaultdict(int)
        d2 = collections.defaultdict(int)
        n = len(secret)
        for i in range(n):
            if secret[i] == guess[i]:
                B += 1
            else:
                d1[secret[i]] += 1
                d2[guess[i]] += 1
        for key in d1:
            C += min(d1[key], d2[key])
        return str(B) + 'A' + str(C) + 'B'



data = Solution()
secret = "1807"
guess = "7810"
print(data.getHint(secret, guess))
